/* eslint-disable @typescript-eslint/no-require-imports */
import { config } from 'ice';
import { IEnv } from './config';

type TArmsEnv = 'prod' | 'gray' | 'pre' | 'daily' | 'local';

const envMap = (env: IEnv): TArmsEnv => {
  switch (env) {
    case 'prod':
      return env;
    case 'uat':
      return 'pre';
    case 'test':
      return 'daily';
    case 'dev':
      return 'local';
    default:
      return 'local';
  }
};

const BrowserLogger = require('alife-logger');

/**
 * 阿里云 ARMS 前端监控配置
 * {@see https://help.aliyun.com/document_detail/58652.html}
 */
export const __bl = BrowserLogger.singleton({
  // NOTE: 本地联调时不上报
  disabled: config.env === 'local',
  // TODO: 务必替换成你自己站点的pid
  pid: '',
  appType: 'web',
  imgUrl: 'https://arms-retcode.aliyuncs.com/r.png?',
  environment: envMap(config.env),
  sendResource: true,
  enableLinkTrace: true,
  behavior: true,
  // NOTE: 默认关闭了API自动上报。已在 @/utils/request 中配置
  disableHook: true,
  // 忽略指定URL/API/JS错误。符合规则的日志将被忽略且不会被上报
  ignore: {
    ignoreApis: ['https://quickaplus-api.ab-inbev.cn'],
    ignoreErrors: [
      // https://github.com/ant-design/ant-design/issues/23246
      /^ResizeObserver loop.*$/,
      // https://help.aliyun.com/document_detail/88579.html#section-ujs-hz3-fhb
      /^Script error\.?$/,
    ],
  },
});
